// class Queue {
//     constructor () {
//       this.count = 0
//       this.lowestCount = 0
//       this.items = {}
//     }
// }


class Queue {
    constructor () {
      this.count = 0
      this.lowestCount = 0
      this.items = {}
    }
    size () {
      return this.count - this.lowestCount
    }
    isEmpty () {
      return this.size() === 0
    }
    enqueue (element) {
      this.items[this.count] = element
      this.count++
    }
    dequeue () {
      if (this.isEmpty()) {
        return undefined
      }
      const result = this.items[this.lowestCount]
      delete this.items[this.lowestCount]
      this.lowestCount++
      return result
    }
    peek () {
      if (this.isEmpty()) {
        return undefined
      }
      return this.items[this.lowestCount]
    }
    clear () {
      this.count = 0
      this.lowestCount = 0
      this.items = {}
    }
    toString () {
      if (this.isEmpty()) {
        return ''
      }
      let objStr = this.items[this.lowestCount]
      for(let i = this.lowestCount + 1; i < this.count; i++) {
        objStr = `${objStr},${this.items[i]}`
      }
      return objStr
    }
}


const queue = new Queue()
console.log(queue.isEmpty())  // true
queue.enqueue('AAA')
queue.enqueue('BBB')
queue.enqueue('CCC')
console.log(queue.isEmpty())  // false
console.log(queue.size())     // 3
console.log(queue.toString()) // AAA,BBB,CCC
console.log(queue.peek())     // AAA
console.log(queue.dequeue())  // AAA
queue.clear()
console.log(queue.isEmpty())  // true


/* 导出变量和函数 */
export { Queue };